﻿#pragma execution_character_set("utf-8")

#include "aivoicepartner.h"
#include "ui_aivoicepartner.h"
#include <QDebug>
#define syslog qDebug()

AIVoicePartner::AIVoicePartner(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::AIVoicePartner)
{
    ui->setupUi(this);
    audio_dev = new Audio_dev(this);
    connect(audio_dev, &Audio_dev::msg_to_ui, this, &AIVoicePartner::udatelog);
    foreach(QAudioDeviceInfo devinfo, audio_dev->AvailableAudioDevs())
    {
        ui->audiodevs->addItem(devinfo.deviceName());
    }
    xunfei_iat = new Xunfei_iat(this);
    connect(xunfei_iat, &Xunfei_iat::msg_to_ui, this, &AIVoicePartner::udatelog);
    connect(this, &AIVoicePartner::call_sendAudio, xunfei_iat, &Xunfei_iat::sendAudio);
}

AIVoicePartner::~AIVoicePartner()
{
    delete ui;
}

void AIVoicePartner::udatelog(QString content)
{
    ui->runlog->append(content);
}

void AIVoicePartner::on_act_record_pressed()
{
    //按键按下，开始录音，直到按键释放
    audio_dev->start_record();
}

void AIVoicePartner::on_act_record_released()
{
    //按键释放，结束录音
    audio_dev->stop_record();
    emit call_sendAudio();
}

void AIVoicePartner::on_sendmsg_clicked()
{
    emit call_sendAudio();
}

void AIVoicePartner::on_initsys_clicked()
{
    ui->runlog->clear();
}

void AIVoicePartner::on_audiodevs_currentIndexChanged(int index)
{
    audio_dev->dev_change(index);
}
